const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const model = mongoose.model.bind(mongoose);
const ObjectId = mongoose.Schema.Types.ObjectId;

const productSchema = Schema({
  id: ObjectId,
  total: Number,
  name: String,
  image: String,
  price: Number,
  description: String,
  manufacturer: { type: ObjectId, ref: 'Manufacturer' }
});

const manufacturerSchema = Schema({
  id: ObjectId,
  name: String,
});

const buyItemSchema = Schema({
  userId: ObjectId,
  userName: String,
  userEmail: String,
  id: ObjectId,
  count: Number,
});

const Product = model('Product', productSchema);
const Manufacturer = model('Manufacturer', manufacturerSchema);
const buyItem = model('buyItem', buyItemSchema);

module.exports = { Product, Manufacturer, buyItem };